package com.all.learning.concurrent.demo;//package demo;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.slkj.qzgw.common.util.AESUtil;
//import com.slkj.qzgw.common.util.MD5Util;
//import com.slkj.qzgw.common.util.RSAUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang.StringUtils;
//import org.apache.http.HttpResponse;
//import org.apache.http.client.HttpClient;
//import org.apache.http.client.methods.HttpPost;
//import org.apache.http.entity.StringEntity;
//import org.apache.http.impl.client.DefaultHttpClient;
//import org.apache.http.protocol.HTTP;
//import org.apache.http.util.EntityUtils;
//
///**
// * Created by daixiaohu on 2019/2/28.
// */
//@Slf4j
//public class TestDemo {
//    static String ADD_URL = "http://sit-gateway.vector-fintech.com/qzgw-app/gate/invoke";
//
//    public static void main(String[] args) throws Exception {
//        String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDGkO3fNvIwfbfVW4eUM8kacIykSJwS7kHDL51ofUfKurRXXgNp1K7CmgK2w6UVx+TCY3tqvCFROMtK/y+13ZESqwdb2ADusAeiFF08KyUnEp8IKTdc6qK9svfvWO1HA7eBo/v9gipEzOd2/smWOgpkB0exvR4tFfjTCoAtpVGDzwIDAQAB";//前置网关
//        String key = AESUtil.getAutoCreateAESKey();
//
//        String param = "{\"orderNo\":\"20190524154302348221\"}";
//
//        System.out.println("param:" + param);
//        String randomKey = AESUtil.getAutoCreateAESKey();//生成随机数
//        String encryData = AESUtil.encryptByAES(param, randomKey);//对body对称加密
//        key = RSAUtil.encryptByPublicKey(randomKey, publicKey);//对随机数进行非对称加密
//        String signData = MD5Util.md5(encryData);//对加密报文进行md5
//        Header header = new Header();
//        header.setOrgCode("jtns");//机构码
//        header.setOrgPwd("qtcq67FY*9ntbynn");//机构用户密码
//        header.setOrgUser("jtns");//机构用户
//        header.setServiceCode("QueryRepayPlan");//服务编码
//        header.setAgencyCode("P0000003");//产品映射编码
//        header.setKey(key);
//        CommonRequest request = new CommonRequest();
//        Body body = new Body();
//        body.setEncryData(encryData);
//        body.setSignData(signData);
//        request.setHeader(header);
//        request.setBody(body);
//
//        String jsonstr = JSON.toJSONString(request);
//        HttpPost httpPost = new HttpPost(ADD_URL);
//        HttpClient httpClient = new DefaultHttpClient();
//        httpPost.setHeader(HTTP.CONTENT_TYPE, "application/json");
//        StringEntity se = new StringEntity(jsonstr);
//        se.setContentType("application/json");
//        se.setContentEncoding("UTF-8");
//        httpPost.setEntity(se);
//        System.out.print("开始调用" + jsonstr);
//        HttpResponse response = httpClient.execute(httpPost);
//        System.out.print("response:" + response);
//        //输出调用结果
//        if (response != null && response.getStatusLine().getStatusCode() == 200) {
//            String result = EntityUtils.toString(response.getEntity());
//            JSONObject obj = JSONObject.parseObject(result);
//            JSONObject responseMesg = obj.getJSONObject("message");
//          String returnCode=responseMesg.getString("returnCode");
//            JSONObject responseData = obj.getJSONObject("body");
//            if ("0000000".equals(returnCode)) {
//                String encryData1 = responseData.getString("encryData");
//                String signData1 = responseData.getString("signData");
//                if (StringUtils.isNotBlank(encryData1)) {
//                    if (!signData1.equals(MD5Util.md5(encryData1))) {
//                            System.out.println("验签失败");
//                    }
//                    JSONObject reponseHeader = obj.getJSONObject("header");
//                    String key1 = reponseHeader.getString("key");
//                    String randomKey1 = RSAUtil.decryptByPublicKey(key1, publicKey);
//                    System.out.println("解密出的随机key:" + randomKey1);
//                    String decryptData1 = AESUtil.decryptByAES(encryData1, randomKey1);
//                    System.out.println("解密出的数据:" + decryptData1);
//                }
//            }
//
//
//
//
//        }
//
//
//    }
//}
